package com.wuliu.business.sys;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.wuliu.model.sys.User;
import com.wuliu.util.DbPool;

public class UserObj {
	public static User getUserById(String id){
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		User user = new User();
		if(id==null || id.equals(""))
			return user;
		String strsql = "SELECT * FROM WL_USER WHERE USER_ID=?";
		try{
			conn = DbPool.getConnection();
			pstmt = conn.prepareStatement(strsql);
			pstmt.setString(1,id);
			rs = pstmt.executeQuery();
			if(rs.next()){
				user.setUserId(rs.getString("USER_ID"));
				user.setUserAccount(rs.getString("USER_ACCOUNT"));
				user.setUserPwd(rs.getString("USER_PWD"));
				user.setUserName(rs.getString("USER_NAME"));
				user.setUserDesc(rs.getString("USER_DESC"));
				user.setUserTel(rs.getString("USER_TEL"));
				user.setUserSpot(rs.getString("USER_SPOT"));
				user.setAddBy(rs.getString("ADD_BY"));
				user.setAddDate(rs.getString("ADD_DATE"));
				user.setAddTime(rs.getString("ADD_TIME"));
				user.setUpdBy(rs.getString("UPD_BY"));
				user.setUpdDate(rs.getString("UPD_DATE"));
				user.setUpdTime(rs.getString("UPD_TIME"));
				user.setActiveFlag(rs.getString("ACTIVE_FLAG"));
			}
		}catch(SQLException sqlE){
			sqlE.printStackTrace();
		}finally{
			DbPool.close(conn, pstmt, rs);
		}
		return user;
	}
	public static User getUserByAccount(String account){
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		User user = new User();
		if(account==null || account.equals(""))
			return user;
		String strsql = "SELECT * FROM WL_USER WHERE USER_ACCOUNT=?";
		try{
			conn = DbPool.getConnection();
			pstmt = conn.prepareStatement(strsql);
			pstmt.setString(1,account);
			rs = pstmt.executeQuery();
			if(rs.next()){
				user.setUserId(rs.getString("USER_ID"));
				user.setUserAccount(rs.getString("USER_ACCOUNT"));
				user.setUserPwd(rs.getString("USER_PWD"));
				user.setUserName(rs.getString("USER_NAME"));
				user.setUserDesc(rs.getString("USER_DESC"));
				user.setUserTel(rs.getString("USER_TEL"));
				user.setUserSpot(rs.getString("USER_SPOT"));
				user.setAddBy(rs.getString("ADD_BY"));
				user.setAddDate(rs.getString("ADD_DATE"));
				user.setAddTime(rs.getString("ADD_TIME"));
				user.setUpdBy(rs.getString("UPD_BY"));
				user.setUpdDate(rs.getString("UPD_DATE"));
				user.setUpdTime(rs.getString("UPD_TIME"));
				user.setActiveFlag(rs.getString("ACTIVE_FLAG"));
			}
		}catch(SQLException sqlE){
			sqlE.printStackTrace();
		}finally{
			DbPool.close(conn, pstmt, rs);
		}
		return user;
	}
}
